#include "xmlsaxhandler.hpp"

XMLSaxHandler::XMLSaxHandler(){
    inBibstyleTag = false;
}

bool XMLSaxHandler::startDocument()
{
    inBibstyleTag = false;
    return true;
}

bool XMLSaxHandler::endElement( const QString&, const QString&, const QString &name )
{
    if( name == "bibstyle" )
        inBibstyleTag = false;
    return true;
}

bool XMLSaxHandler::startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs )
{
    if( inBibstyleTag && name == "style" )
    {
        int id;
        QString lt,lc,lw,pt,ps,pi;
        for(int i=0; i<attrs.count(); ++i)
        {
            if(attrs.localName(i) == "id")
                id = attrs.value(i).toInt();
            else if(attrs.localName(i) == "lt")
                lt = attrs.value(i);
            else if(attrs.localName(i) == "lc")
                lc = attrs.value(i);
            else if(attrs.localName(i) == "lw")
                lw = attrs.value(i);
            else if(attrs.localName(i) == "pt")
                pt = attrs.value(i);
            else if(attrs.localName(i) == "ps")
                ps = attrs.value(i);
            else if(attrs.localName(i) == "pi")
                pi = attrs.value(i);
        }
        ChartStyleFactory::Instance().addStyle(id,lt.toUtf8().constData(),lc.toUtf8().constData(),
                                               lw.toUtf8().constData(),pt.toUtf8().constData(),
                                               ps.toUtf8().constData(),pi.toUtf8().constData());
    }
    else if( name == "bibstyle")
        inBibstyleTag = true;
    return true;
}

